import React, { useState, useEffect } from "react";
import { Button, message, Switch } from "antd";
import { invokeAPi, invokeAsyncAPi } from "@/xz-fn.js";
import "../index.css";
const App = ({ handleCancel }) => {
  const [checkValue, setCheckValue] = useState(true);
  const changeCheckValue = (value) => {
    setCheckValue(value);
    invokeAPi("xz_set_win_start", value);
    message.success(`开机自动启动 ${value ? "开启" : "关闭"} 成功`);
  };

  const handleReset = async () => {
    setCheckValue(true);
    invokeAPi("xz_set_win_start", true);
  };

  const handleSave = () => {};
  useEffect(() => {
    invokeAsyncAPi("xz_get_win_start ").then(async (res) => {
      console.log(res);
      setCheckValue(res);
    });
  }, []);
  return (
    <>
      <div className="content-top h-[420px] flex justify-between">
        <div>开机自动启动</div>
        <Switch value={checkValue} onChange={changeCheckValue} />
      </div>
      <div className="content-bottom flex items-center justify-end">
        <Button color="default" variant="link" onClick={handleCancel}>
          取消
        </Button>
        <Button type="link" onClick={handleReset}>
          重置
        </Button>
        <Button color="primary" variant="link" onClick={handleSave}>
          保存
        </Button>
      </div>
    </>
  );
};
export default App;
